<template>
    <view class="main">
        <view class="ip-item">
            <input type="text" placeholder="请输入圈子名称" placeholder-class="ip" v-model="formData.name">
        </view>
        <view class="ip-item" @click="$goUrl('/pages/index/pages/industry')">
            <input type="text" placeholder="请选择所属行业" v-model="formData.industry" disabled placeholder-class="ip">
            <image src="/static/icon/down.svg" mode="widthFix" />
            <view class="block"></view>
        </view>
    </view>
    <view class="btns">
        <Button @clickButton="carete" :loading="loading" loading-text="创建中" />
    </view>
</template>

<script setup>
import { ref } from 'vue';
import { onLoad } from '@dcloudio/uni-app'
import { createCircle } from '@/api/apiList'

const formData = ref({
    industryId: '',
    industry: '',
    name: '',
    way: '1',
    type: 0
})

const getPreviousPageType = () => {
    uni.$on('getType', (data) => {
        if (data) {
            formData.value.industryId = data.data[0].id
            formData.value.industry = data.data[0].name
            console.log(formData.value, 'formData.value')
        }
    })
}

onLoad(() => {
    getPreviousPageType()
})

const loading = ref(false)
const carete = async () => {
    if (!formData.value.name) {
        uni.showToast({
            title: '请输入圈子名称',
            icon: 'none'
        })
        return
    }
    if (!formData.value.industryId) {
        uni.showToast({
            title: '请选择行业',
            icon: 'none'
        })
        return
    }
    loading.value = true
    const res = await createCircle(formData.value)
    if (res.code == 200) {
        setTimeout(() => {
            loading.value = false
            uni.showToast({
                title: '圈子创建成功',
                icon: 'none'
            })
            uni.navigateBack()
        }, 2000);
    }

}
</script>

<style lang="scss" scoped>
.main {
    padding: 30rpx;
}

.btns {
    padding: 0 30rpx;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 66rpx;
}
</style>